-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NatGateway data source #1294
Conversation
Realized I will need to return these values...
Is it against best practice to use your travis as a debugger? |
This needs thoroughly tested and reviewed but we might have a working PR. Wish I could test on my local machine in Terraform. Instructions on how would be greatly appreciated. |
I will update aws/provider.go and the website documentation tomorrow. |
Here's how I am locally testing.
I am running terraform 0.9.latest; but I do also have terraform 0.10.0-dev (which is master). The provider docs say 0.10 is required. That hasn't bit me yet - other things have. |
Any success? Do we have a working pr? I will work on it again tomorrow.
…On Jul 31, 2017 10:45 PM, "Clinton Wolfe" ***@***.***> wrote:
Here's how I am locally testing.
1. Install go and set GOPATH, per golang.org
2. Per https://github.com/terraform-providers/terraform-provider-
aws#developing-the-provider , I cloned the AWS provider under the
GOPATH, from the terraform-providers repo.
3. In that local repo, I then added your repo as a remote, and pulled
your branch.
4. I set my AWS... environment variables to an empty test account.
5. I ran the acceptance tests using
make testacc TEST=./aws TESTARGS="-run=TestAccDataSourceAwsNatGateway"
I am running terraform 0.9.latest; but I do also have terraform 0.10.0-dev
(which is master). The provider docs say 0.10 is required. That hasn't bit
me yet - other things have.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQTJt_ZYzuELe7HwgcO3e8y6R8jLxcEUks5sTpFTgaJpZM4Oo6-G>
.
|
It's close - missing some pieces in the acctest config; a NGW resource requires a subnet, so that means a data lookup for a subnet; which likely means a data lookup for the default VPC... I may look around at other acctests and see how they handled that - not sure we should assume a default VPC is present, or just make what we need. Probably the latter. Also I've added it to the data source list for the provider, but it's not picking it up. I imagine that is something silly. I'll put another hour or two into it tonight, then open a PR on your repo from my fork.
|
Thanks =)
…On Jul 31, 2017 10:59 PM, "Clinton Wolfe" ***@***.***> wrote:
It's close - missing some pieces in the acctest config; a NGW resource
requires a subnet, so that means a data lookup for a subnet; which likely
means a data lookup for the default VPC... I may look around at other
acctests and see how they handled that - not sure we should assume a
default VPC is present, or just make what we need. Probably the latter.
Also I've added it to the data source list for the provider, but it's not
picking it up. I imagine that is something silly. I'll put another hour or
two into it tonight, then open a PR on your repo from my fork.
***@***.*** terraform-provider-aws]$ make testacc TEST=./aws TESTARGS="-run=TestAccDataSourceAwsNatGateway"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAwsNatGateway -timeout 120m
=== RUN TestAccDataSourceAwsNatGateway
--- FAIL: TestAccDataSourceAwsNatGateway (1.36s)
testing.go:428: Step 0 error: Configuration is invalid.
Warnings: []string(nil)
Errors: []string{"aws_nat_gateway.test: \"allocation_id\": required field is not set", "aws_nat_gateway.test: \"subnet_id\": required field is not set", "aws_nat_gateway.test: : invalid or unknown key: tags", "data.aws_nat_gateway.test_by_id: Provider doesn't support data source: aws_nat_gateway", "data.aws_nat_gateway.test_by_tags: Provider doesn't support data source: aws_nat_gateway"}
FAIL
exit status 1
FAIL github.com/terraform-providers/terraform-provider-aws/aws 1.388s
make: *** [testacc] Error 1
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQTJtxljPPXz72ZHdGBWwc3wB4VZPM3Aks5sTpSAgaJpZM4Oo6-G>
.
|
@Ninir @radeksimko When will this be reviewed by a team member and merged? |
You can now add |
Adding back
would help with #1238 I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @shadycuz
This seems very good to me! 👍
$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAwsNatGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAwsNatGateway -timeout 120m
=== RUN TestAccDataSourceAwsNatGateway
--- PASS: TestAccDataSourceAwsNatGateway (212.44s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 212.472s
Just left a few cosmetic changes, and a request to add tags handling.
Thanks a lot for the work! 👍
aws/data_source_aws_nat_gateway.go
Outdated
Optional: true, | ||
Computed: true, | ||
}, | ||
"filter": ec2CustomFiltersSchema(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add the tags part, following @ewbankkit 's comment?
aws/data_source_aws_nat_gateway.go
Outdated
func dataSourceAwsNatGatewayRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
log.Printf("[DEBUG] Reading NAT Gateways.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this above line 85 and update it using something like:
log.Printf("[DEBUG] Reading NAT Gateway: %s", req)
This will print every parameters, for a better debugging :)
@@ -140,6 +140,9 @@ | |||
<li<%= sidebar_current("docs-aws-datasource-kms-secret") %>> | |||
<a href="/docs/providers/aws/d/kms_secret.html">aws_kms_secret</a> | |||
</li> | |||
<li<%= sidebar_current("docs-aws-datasource-nat-gateway") %>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the extra plus signs on the lines below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have been removed
Provides details about a specific Nat Gateway | ||
--- | ||
|
||
# aws\_nat\_gateway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Antislashes are not needed anymore in titles, as per one of @sethvargo 's contributions :)
data "aws_nat_gateway" "default" { | ||
|
||
subnet_id = "${var.subnet_id}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove additional spaces also? will make it easier to read
Nat Gateway in the current region. The given filters must match exactly one | ||
Nat Gateway whose data will be exported as attributes. | ||
|
||
* `nat_gateway_id` - (Optional) The id of the specific Nat Gateway to retrieve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can name it id
indeed
* `subnet_id` - (Optional) The id of subnet that the Nat Gateway resides in. | ||
|
||
* `vpc_id` - (Optional) The id of the VPC that the Nat Gateway resides in. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove additional spaces between list items? thanks 😄
@Ninir Waiting for time ;) maybe this weekend |
Hey @shadycuz Do you think you can find time for that, or do you mind someone to take over this PR? |
@Ninir I'll start pushing updates tonight |
…form-provider-aws into feat/natgatewayDatasource
@Ninir Updated |
@ewbankkit Can you explain your comment? #1294 (comment) |
@shadycuz I was commenting that the ENI ID/allocation ID of the NAT gateway should be outputs of the data source as that should address the linked-to issue.
as attributes but they're not declared in the data source's
|
@ewbankkit for the attributes I export them because if you find a match they are available, however when searching for a nat gateway you are only allowed to use certain attributes. http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-nat-gateways.html I had thought about cheating, grabbing all natgateways in the aws account and then looping through them to find those attributes but after discussing it with someone else we decided to leave as is for now. Yes I think the names should match what is in the resources, I will fix any that are different. |
@ewbankkit updated attribute names to match the resource. @Ninir Ready =) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the work @shadycuz! :)
$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAwsNatGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAwsNatGateway -timeout 120m
=== RUN TestAccDataSourceAwsNatGateway
--- PASS: TestAccDataSourceAwsNatGateway (216.63s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 216.664s
Thanks @Ninir , looking forward to seeing it in a release! Thanks @clintoncwolfe |
|
||
for _, address := range ngw.NatGatewayAddresses { | ||
if *address.AllocationId != "" { | ||
d.Set("allocation_id", address.AllocationId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ninir I tried using this data source and found these attributes are not being included in the output. Running terraform with DEBUG logging I see this warning:
2017/11/07 13:04:19 [WARN] Output interpolation "private_ip" failed: Resource 'data.aws_nat_gateway.default' does not have attribute 'private_ip' for variable 'data.aws_nat_gateway.default.private_ip'
I do see the values in the AWS response logged by Terraform:
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <DescribeNatGatewaysResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <requestId>1aa2f2a0-c316-4b83-808b-7402d5cfaa32</requestId>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <natGatewaySet>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <item>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <createTime>2017-11-03T23:34:36.000Z</createTime>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <natGatewayAddressSet>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <item>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <allocationId>eipalloc-xxxxxx</allocationId>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <networkInterfaceId>eni-xxxxxx</networkInterfaceId>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <privateIp>172.20.8.29</privateIp>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <publicIp>34.237.xyz.xyz</publicIp>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: </item>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: </natGatewayAddressSet>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <natGatewayId>nat-xxxxxxxx</natGatewayId>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <state>available</state>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <subnetId>subnet-xxxxxxxx</subnetId>
2017-11-07T13:04:17.147-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: <vpcId>vpc-xxxxxxxx</vpcId>
2017-11-07T13:04:17.148-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: </item>
2017-11-07T13:04:17.148-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: </natGatewaySet>
2017-11-07T13:04:17.148-0800 [DEBUG] plugin.terraform-provider-aws_v1.2.0_x4: </DescribeNatGatewaysResponse>
Does the list of output-able values have to be included in the Schema definition? https://github.com/terraform-providers/terraform-provider-aws/pull/1294/files#diff-5264f6e572425a4527111c5172455cf6R16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #2209
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
I never used go and I'm not familiar with the inter workings of terraform but I do need this data source to fix #1293 and #1238. I had issues with getting this to compile so I could not run tests (fat chance they would have passed). Looking for help on how to proceed.
Thanks,
Levi
I'm guessing I can build that dir tree and clone those repos into it?